//index.js
//获取应用实例
// const app = getApp()
const db = wx.cloud.database();
Page({
  lide: function (e) {
    // console.log(e)
    var a = e.currentTarget.dataset;
    this.data.list.map((item) => {
      item.isShow = false
    })
    this.data.list[a.index].isShow = true
    switch (a.index || 0) {
      case 0:
        db.collection('computeList').get().then(res => {
          // this.data.riceProduction=res.data   异步有延迟
          this.setData({
            riceProduction: res.data
          })
        })
        break;
      case 1:
        db.collection('closeList').get().then(res => {
          // this.data.riceProduction=res.data   异步有延迟
          this.setData({
            riceProduction: res.data
          })
        })
        break;
      case 2:
        db.collection('ballList').get().then(res => {
          this.setData({
            riceProduction: res.data
          })
        })
        break;
      case 3:
        db.collection('phoneList').get().then(res => {
          // this.data.riceProduction=res.data   异步有延迟
          this.setData({
            riceProduction: res.data
          })
        })
        break;
      case 4:
        this.data.icon = '11111'
        break;
      case 5:
        this.data.icon = '2222'
        break;
      case 6:
        this.data.icon = '3333'
        break;
      case 7:
        this.data.icon = '4444'
        break;
      case 8:
        this.data.icon = '55555'
        break;
      case 9:
        this.data.icon = '66666'
        break;
      case 10:
        this.data.icon = '77777'
        break;
      case 11:
        this.data.icon = '8888'
        break;
      case 12:
        this.data.icon = '9999'
        break;
      case 13:
        this.data.icon = 'sssss'
        break;
      case 14:
        this.data.icon = '撒擦擦擦'
        break;
      case 15:
        this.data.icon = '擦擦擦擦擦擦擦'
        break;
      case 16:
        this.data.icon = '当初V我不空啥vb哦I'
        break;
      default:
        this.data.icon = ''
    }
    this.setData({
      riceProduction: this.data.riceProduction,
      list: this.data.list
    })
  },
  random: function (e) {
    wx.navigateTo({
      url: '../search/index'
    })
    // let value = e.detail;
    switch (value) {
      case '幽默笑话':
        this.setData({
          value: ''
        })
        wx.navigateTo({
          url: '/pages/joke/index'
        })
        break;
      case '周公解梦':
        this.setData({
          value: ''
        })
        wx.navigateTo({
          url: '/pages/dream/index',
        })
        break;
      case '数据库测试':
        this.setData({
          value: ''
        })
        wx.navigateTo({
          url: '/pages/mangoDB/index',
        })
        break;
        case '新闻':
          this.setData({
            value: ''
          })
          wx.navigateTo({
            url: '../oder/index',
          })
          break;
      default:
        ''
    }
  },
  toBayCar: function (e) {
    var da = e.currentTarget.dataset.it
    wx.navigateTo({
      url: '../buyCar/index',
      success(res) {
        res.eventChannel.emit('parasite', da)
      }
    })
  },
  data: {
    inputShowed: false,
    value: "",
    list: [
      { title: '电子产品', id: 1, isShow: true },
      { title: '衣服', id: 2, isShow: false },
      { title: '运动装', id: 3, isShow: false },
      { title: '手机', id: 4, isShow: false }
    ],
    riceProduction: [],
  },
  onLoad: function () {
    this.setData({
      search: this.search.bind(this),
      riceProduction: this.data.riceProd
    })
    db.collection('computeList').get().then(res => {
      // 用户进入界面初始化 电子产品数据，因第一次没有点击产品列表
      this.setData({
        riceProduction: res.data
      })
    })
  },
  search: function (value) {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve([{ text: '搜索结果', value: 1 }, { text: '搜索结果2', value: 2 }])
      }, 200)
    })
  },
  selectResult: function (e) {
    // console.log('select result', e.detail)
  },
})
